package com.gm.wholesale.module.order.view.orderManger;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.gm.wholesale.R;
import com.gm.wholesale.module.aftersale.bean.AftersalesBean;
import com.gm.wholesale.module.order.bean.OrderDetailBean;

public class OrderGoodInfoItemView extends LinearLayout {
    private Context mContext;
    private TextView afterSalesView;
    private TextView goodNameTv;
    private TextView goodNumTv;
    private TextView goodUnitTv;
    private TextView goodPriceTv;
    private TextView totalPriceTv;

    public OrderGoodInfoItemView(Context context) {
        super(context);
        initView(context);
    }

    public OrderGoodInfoItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.list_order_detail_item, this);
        afterSalesView = findViewById(R.id.afterSalesView);
        goodNameTv = findViewById(R.id.goodNameTv);
        goodNumTv = findViewById(R.id.goodNumTv);
        goodUnitTv = findViewById(R.id.goodUnitTv);
        goodPriceTv = findViewById(R.id.goodPriceTv);
        totalPriceTv = findViewById(R.id.totalPriceTv);
    }

    public void showView(OrderDetailBean.OrderDetailsDTO good) {
        if (good != null) {
            goodNameTv.setText(good.getSkuName());
            goodNumTv.setText(good.getQuantity());
            goodPriceTv.setText(good.getUnitPrice());
            goodUnitTv.setText(good.getOutgoingUnitName());
            totalPriceTv.setText(getText(good.getSubtotal()));
        }
    }

    public void showView(AftersalesBean.ItemsBean aftersalesBean) {
        if (aftersalesBean != null) {
            goodNameTv.setText(aftersalesBean.getSkuName());
            goodNumTv.setText(aftersalesBean.getQuantity());
            goodPriceTv.setText(aftersalesBean.getUnitPrice());
            goodUnitTv.setText(aftersalesBean.getUnitName());
            totalPriceTv.setText(aftersalesBean.getSubtotal());
            setTextViewColor(goodNameTv);
            setTextViewColor(goodNumTv);
            setTextViewColor(goodPriceTv);
            setTextViewColor(goodUnitTv);
            setTextViewColor(totalPriceTv);
            afterSalesView.setVisibility(VISIBLE);
        }
    }

    private void setTextViewColor(TextView textView) {
        textView.setTextColor(mContext.getResources().getColor(R.color.color_F13835));
    }

    private String getText(String text) {
        if (TextUtils.isEmpty(text)) {
            return "";
        }
        return text;
    }
}
